package com.climber.spb_rabbitmq.spb_delayqueue_1.controller;

import com.climber.spb_rabbitmq.spb_delayqueue_1.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class MessageController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 发布消息
     *以队列为单位设置消息的延时
     * @param content
     */
    @GetMapping("/sendMessage/{content}")
    public void sendMessage(@PathVariable("content") String content) {
        System.out.println(new Date().toString());
        rabbitTemplate.convertAndSend(RabbitMQConfig.X_EXCHANGE, "XA", "消息来自ttl为10s的队列:" + content);
        rabbitTemplate.convertAndSend(RabbitMQConfig.X_EXCHANGE, "XB", "消息来自ttl为20s的队列:" + content);
    }


}